﻿using System;
using System.Collections.Generic;

namespace Cache.Redis
{
    public interface ICacheHelper
    {
        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        bool Exists(string key);

        /// <summary>
        /// 获取对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        T Get<T>(string key);

        /// <summary>
        /// 获取对象
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        object Get(string key);

        /// <summary>
        ///             获取全部key
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cacheKeyPrefix"></param>
        /// <returns></returns>
        System.Collections.Generic.List<string> GetAllKey();

        /// <summary>
        ///             获取这个前缀的全部key
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cacheKeyPrefix"></param>
        /// <returns></returns>
        System.Collections.Generic.List<string> GetAllKey(string cacheKeyPrefix);

        /// <summary>
        /// 获取一系列对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cacheKeyPrefix"></param>
        /// <returns></returns>
        System.Collections.Generic.List<T> GetAll<T>(string cacheKeyPrefix);

        System.Collections.Generic.List<T> GetAll<T>(System.Collections.Generic.List<string> keys);

        /// <summary>
        /// 获取集合数量
        /// </summary>
        /// <param name="listId"></param>
        /// <returns></returns>
        int GetListCount(string listId);

        /// <summary>
        /// 获取hash数量
        /// </summary>
        /// <param name="listId"></param>
        /// <returns></returns>
        int GetHashLength(string listId);

        System.Collections.Generic.List<string> GetAllItemsFromList(string listId);

        System.Collections.Generic.Dictionary<string, string> GetAllEntriesFromHash(string hashId);

        /// <summary>
        /// 添加对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        bool Set<T>(string key, T value);

        /// <summary>
        /// 添加对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="minutes"></param>
        /// <returns></returns>
        bool Set<T>(string key, T value, int minutes);

        bool Set<T>(string key, T value, System.TimeSpan ts);

        /// <summary>
        /// 移除对象
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        bool Remove(string key);

        /// <summary>
        /// 移除这个前缀的所有对象
        /// </summary>
        /// <param name="cacheKeyPrefix"></param>
        void RemoveAll(string cacheKeyPrefix);

        /// <summary>
        /// 从hash表中移除
        /// </summary>
        /// <param name="hashId"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        bool RemoveEntryFromHash(string hashId, string key);

        /// <summary>
        /// 移除所有对象
        /// </summary>
        /// <param name="keys"></param>
        void RemoveAll(System.Collections.Generic.List<string> keys);

        /// <summary>
        /// 全部删除
        /// </summary>
        void FlushAll();

        /// <summary>
        /// 仅redis支持
        /// </summary>
        void Save();

        /// <summary>
        /// 使用队列处理item
        /// </summary>
        /// <param name="key"></param>
        /// <param name="val"></param>
        void EnqueueItem(string key, string val);

        string DequeueItem(string key);

        /// <summary>
        /// 对某个key增加相应的值
        /// </summary>
        /// <param name="key"></param>
        /// <param name="addVal"></param>
        /// <returns></returns>
        long Increment(string key, int addVal);

        int Increment(string hashId, string key, int incrementBy);

        bool SetEntryInHashIfNotExists(string hashId, string key, string value);

        bool SetEntryInHash(string hashId, string key, string value);

        string GetHash(string hashId, string key);

        bool SetEntryInHash<T>(string hashId, string key, T value);

        bool SetEntryInHash<T>(string hashId, string key, T value, int minutes);

        T GetHash<T>(string hashId, string key);

        bool Add<T>(string key, T value);

        bool Add<T>(string key, T value, System.TimeSpan expireTime);

        void AddItemToList(string listId, string value);

        void AddRangeToList(string listId, System.Collections.Generic.List<string> values);
    }
}
